<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: 'index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <el-row :span="8">
        <el-input placeholder="请输入内容">
          <el-button slot="append" icon="el-icon-search"></el-button>
        </el-input>
      </el-row>
      <el-table :data="orderList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status">
          <template slot-scope="scope">
            <el-popover trigger="hover" placement="top">
              <p>购买人: {{ scope.row.order_fapiao_title }}</p>
              <p v-if="scope.row.order_pay === '0'">支付方式: 未支付</p>
              <p v-else-if="scope.row.order_pay === '1'">支付方式: 支付宝</p>
              <p v-else-if="scope.row.order_pay === '2'">支付方式: 微信</p>
              <p v-else>支付方式: 银行卡</p>
              <div slot="reference" class="name-wrapper">
                <el-tag v-if="scope.row.pay_status === '0'" type="danger"
                  >未付款</el-tag
                >
                <el-tag type="success" v-else>已付款</el-tag>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间" prop="create_time">
          <template slot-scope="scope">
            {{ scope.row.create_time | dataFormat }}
          </template></el-table-column
        >
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="showBox(scope.row.order_id)"
            ></el-button>
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-delete"
              @click="SeleteBox"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 8, 9, 18]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      <!-- 修改地址 -->
      <el-dialog title="修改信息" :visible.sync="dialogFormVisible">
        <el-form :model="addressFrom" ref="addressFromRef" label-width="100px">
          <el-form-item label="订单状态">
            <el-select v-model="addressFrom.is_send" placeholder="是否发货">
              <el-option label="已经发货" value="1"></el-option>
              <el-option label="未发货" value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="订单价格">
            <el-input
              v-model="addressFrom.order_price"
              type="number"
            ></el-input>
          </el-form-item>
          <el-form-item label="支付方式">
            <el-select
              v-model="addressFrom.order_pay"
              placeholder="请选择付款方式"
            >
              <el-option label="未支付" value="0"></el-option>
              <el-option label="支付宝" value="1"></el-option>
              <el-option label="微信" value="2"></el-option>
              <el-option label="银行卡" value="3"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="支付状态">
            <el-select v-model="addressFrom.pay_status" placeholder="是否付款">
              <el-option label="已付款" value="1"></el-option>
              <el-option label="未付款" value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitValue">确 定</el-button>
        </div>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
      total: 0,
      orderList: [],
      dialogFormVisible: false,
      dialogFormVisibleS: false,
      addressFrom: {
        is_send: "",
        order_price: "",
        order_pay: "",
        pay_status: "",
      },
      OrderId: "",
    };
  },
  created() {
    this.getOderList();
  },
  methods: {
    getOderList() {
      this.$Req.get("/orders", { params: this.queryInfo }).then((res) => {
        const { data, meta } = res.data;
        this.total = data.total;
        this.orderList = data.goods;
      });
    },
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOderList();
    },
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage;
      this.getOderList();
    },
    showBox(OrderId) {
      this.OrderId = OrderId;
      this.dialogFormVisible = true;
    },
    // SeleteBox() {},
    // 编辑
    submitValue() {
      this.dialogFormVisible = false;
      this.$Req.put(`orders/${this.OrderId}`, this.addressFrom).then((res) => {
        const { data, meta } = res.data;
        if (meta.status === 201) {
          this.$message({
            type: "success",
            message: meta.msg,
          });
          this.getOderList();
        }
      });
    },
  },
};
</script>

<style>
.el-main {
  line-height: 0;
}
</style>